package dao

import (
	"gitee.com/shuwenhe/shuwen-mall/utils"
)

type Item struct {
	ID      int
	Title   string
	Author  string
	Price   float64
	Sales   int
	Stock   int
	ImgPath string
}

func GetItems() ([]*Item, error) {
	sql := "select id,title,author,price,sales,stock,img_path from books"
	rows, err := utils.Db.Query(sql)
	if err != nil {
		return nil, err
	}
	var books []*Item
	for rows.Next() {
		book := &Item{}
		rows.Scan(&book.ID, &book.Title, &book.Author, &book.Price, &book.Sales, &book.Stock, &book.ImgPath) // 给book中的字段赋值
		books = append(books, book)                                                                          // 将book添加到books切片中
	}
	return books, nil
}
